package Leetcode.lc206;

import Leetcode.tools.ListNode;

/***
 给你单链表的头节点 head ，请你反转链表，并返回反转后的链表。
 */
public class Sloution {
    public ListNode reverseList(ListNode head) {
        ListNode cur=head,pre=null,temp=null;
        while (cur!=null){
            temp=cur.next;
            cur.next=pre;
            pre=cur;
            cur=temp;
        }
        return pre;
    }

    public static void main(String[] args) {
        Sloution sloution = new Sloution();
        int[] ints = {1, 2, 3, 4, 5};
        ListNode listutils = new ListNode();
        ListNode node = listutils.listBuilder(ints);
        ListNode node1 = sloution.reverseList(node);
        node1.printAll(node1);


    }
}
